<template>
	<view class="content">	
		<view class="item" @click="scan()">
			<text>扫一扫</text>
		</view>
		<navigator :url="'./userlist'" class="item" hover-class="bkclick">
			<view>
				<text>书友</text>
			</view>
		</navigator>
		<navigator :url="'./shuzhailist'" class="item" hover-class="bkclick">
			<view>
				<text>书摘</text>
			</view>
		</navigator>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				
			}
		},
		onLoad() {
			// this.isLoading = true;
			// this.getBookList();
		},
		methods: {
			scan() {
				//  跳转到二维码扫描页面
				// uni.navigateTo({
				//     url: '../scancode/scancode'
				// });
				
				// 允许从相机和相册扫码
				uni.scanCode({
					scanType: ['qrCode','barCode'],
				    success: function (res) {
				        // console.log('条码类型：' + res.scanType);
				        // console.log('条码内容：' + res.result);
						this.getBookinfo(res.result);
				    }
				});
			},
			getBookinfo(isbn) {
				uni.request({
				    url: 'https://www.yedushu.cn/api/scanisbn', // 根据isbn搜索
					data: {
						isbn: isbn
					},
				    success: (res) => {
				        console.log(JSON.stringify(res.data));
						if(res.data != null && res.data != "")
						{
							// 跳转到书籍详情页面
							uni.redirectTo({
							    url: '../books/bookinfo?bookid=' + res.data.book_id + '&bookname=' + res.data.book_name
							});
						} else {
							// 没有搜索到图书的提示
							uni.redirectTo({
							    url: './scanisbn_tishi'
							});
						}
				    }
				});					
			},			
		}
	}
</script>

<style>
	page{
		background: #F8F8F8;
	}
	.content {
		display: flex;
		flex-direction: column;
	}
	.item {
		padding: 10px 20px;
		font-size: 15px;		
		background-color: #FFFFFF;
		margin-bottom: 8px;
	}
	.bkclick {
		background-color: #f3f3f3;
	}
</style>
